package com.dongdongshop.service.impl;

import com.dongdongshop.common.PageResult;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbTypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class TbTypeTemplateServiceImpl implements TbTypeTemplateService {
    @Resource
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Override
    public PageResult<TbTypeTemplate> selectInfoLimitServer(TbTypeTemplate tbTypeTemplate, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbTypeTemplate> list = tbTypeTemplateMapper.selectByName(tbTypeTemplate);
        PageInfo<TbTypeTemplate> page = new PageInfo<>(list);
        PageResult<TbTypeTemplate> pageResult = new PageResult<>(page.getTotal(),page.getList());
        return pageResult;
    }

    @Override
    public int addTypeTemplate(TbTypeTemplate tbTypeTemplate) {
        int i = tbTypeTemplateMapper.insertSelective(tbTypeTemplate);
        return i;
    }

    @Override
    public TbTypeTemplate getSelctById(Long id) {
        TbTypeTemplate template = tbTypeTemplateMapper.selectByPrimaryKey(id);
        return template;
    }

    @Override
    public int updateTypeTemplate(TbTypeTemplate tbTypeTemplate) {
        int i = tbTypeTemplateMapper.updateByPrimaryKeySelective(tbTypeTemplate);
        return i;
    }

    @Override
    public int deleteTypeTemplate(Long id) {
        int i = tbTypeTemplateMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public List<TbTypeTemplate> selectAll() {
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.selectByExample(null);
        return tbTypeTemplates;
    }
}

